package b.h.y.bj.base;

import android.app.Activity;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.ImageButton;
import android.widget.TextView;

import com.jeremyfeinstein.slidingmenu.lib.SlidingMenu;

import b.h.y.bj.MainActivity;
import b.h.y.bj.R;

/**
 * 主页下5个子页面的基类
 * Created by YHB on 2015/12/31.
 */
public class BasePager {

    public Activity mActivity;
    public View mRootView;

    public TextView tvTitle; //标题对象
    public FrameLayout flContent; //内容
    public ImageButton mBtnImage; //菜单按钮
    public ImageButton mBtnPhotoType; //listView 和gridView切换


    public BasePager(Activity activity) {
        this.mActivity = activity;
        initViews();
    }

    /**
     * 初始化布局
     */
    public void initViews() {
        mRootView = View.inflate(mActivity, R.layout.base_pager, null);

        tvTitle = (TextView) mRootView.findViewById(R.id.tv_title);
        flContent = (FrameLayout) mRootView.findViewById(R.id.fl_content);
        mBtnImage = (ImageButton) mRootView.findViewById(R.id.btn_menu);
        mBtnPhotoType = (ImageButton) mRootView.findViewById(R.id.btn_photo);

        mBtnImage.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                toggleSlidingMenu();
            }
        });
    }

    /**
     * 切换slidingmenu状态
     */
    private void toggleSlidingMenu() {
        MainActivity mainActivity = (MainActivity) mActivity;
        mainActivity.getSlidingMenu().toggle();
    }


    /**
     * 初始化数据
     */
    public void initData() {

    }

    /**
     * 设置侧边栏是否开启 true开启 false 关闭
     *
     * @param enable
     */
    public void setSlidingMenuEnable(boolean enable) {
        MainActivity mainUI = (MainActivity) mActivity;
        SlidingMenu slidingMenu = mainUI.getSlidingMenu();
        if (enable) {
            slidingMenu.setTouchModeAbove(SlidingMenu.TOUCHMODE_FULLSCREEN);
        } else {
            slidingMenu.setTouchModeAbove(SlidingMenu.TOUCHMODE_NONE);
        }
    }
}
